#define Maxsize 1000

typedef struct 
{
    int *data;
    int top;
    int min;
} MinStack;


MinStack* minStackCreate() {
    MinStack* obj=(MinStack* )malloc(sizeof(MinStack));
    obj->data = (int*)malloc(sizeof(int) *Maxsize);
    obj->top=-1;
    obj->min=INT_MAX;
    return obj;
}

void minStackPush(MinStack* obj, int val) 
{
    if (obj->top>=Maxsize) 
    {
        return;
    }
    obj->data[++(obj->top)]=val;
    if (val<obj->min) 
    {
        obj->min=val;
    }
}

void minStackPop(MinStack* obj) 
{
    if (obj->top < 0) 
    {
        return;
    }
    obj->top--;
    if (obj->top>=0) 
    {
        obj->min=obj->data[obj->top];
    } else 
    {
        obj->min=INT_MAX;
    }
    for (int i=obj->top;i>=0;i--) 
    {
        if (obj->data[i]<obj->min) 
        {
            obj->min=obj->data[i];
        }
    }
}

int minStackTop(MinStack* obj) 
{
    return obj->data[obj->top];
}

int minStackGetMin(MinStack* obj) 
{
    if (obj->top<0) 
    {
        return -1;
    }
    return obj->min;
}

void minStackFree(MinStack* obj) 
{
    free(obj);
}

/**
 * Your MinStack struct will be instantiated and called as such:
 * MinStack* obj = minStackCreate();
 * minStackPush(obj, val);
 
 * minStackPop(obj);
 
 * int param_3 = minStackTop(obj);
 
 * int param_4 = minStackGetMin(obj);
 
 * minStackFree(obj);
*/